package com.xiyu.service.repository.devops.server;

import com.xiyu.service.vo.infra.devops.server.ServerPageQueryInput;
import com.xiyu.service.model.devops.server.DevopsServer;
import com.xiyu.service.model.devops.server.DevopsServerTable;
import org.babyfish.jimmer.spring.repository.JRepository;
import org.babyfish.jimmer.Page;
import org.springframework.util.StringUtils;

import java.util.List;

public interface DevopsServerRepository extends JRepository<DevopsServer, Long> {
    DevopsServerTable devopsServerTable = DevopsServerTable.$;

    default Page<DevopsServer> pageQuery(ServerPageQueryInput inputVO){
        return sql().createQuery(devopsServerTable)
                .whereIf(StringUtils.hasText(inputVO.getIp()), () -> devopsServerTable.ip().like(inputVO.getIp()))
                        .orderBy(devopsServerTable.id().desc())
                        .select(devopsServerTable).fetchPage(inputVO.getPageNo() - 1, inputVO.getPageSize());
    }

    default List<DevopsServer> listQuery(){
        return sql().createQuery(devopsServerTable)
                .orderBy(devopsServerTable.id().desc())
                .select(devopsServerTable).execute();
    }


}